this.addEventListener('install', function (event) {
  event.waitUntil(this.skipWaiting());
  event.waitUntil(
		caches.open('v1').then(function (cache) {
			return cache.addAll([
				'/',
				'/index.html',
				'/js/vue.min.js',
				'/js/vui.js',
				'/css/vui.css'
			]);
		})
  );
});
this.addEventListener('activate', function (event) {
    event.waitUntil(
        Promise.all([

            // 更新客户端
            this.clients.claim(),

            // 清理旧版本
            caches.keys().then(function (cacheList) {
                return Promise.all(
                    cacheList.map(function (cacheName) {
                        if (cacheName !== 'v1') {
                            return caches.delete(cacheName);
                        }
                    })
                );
            })
        ])
    );
})
this.addEventListener('fetch', function(event) {
	console.log(event)
  event.respondWith(
    caches.match(event.request).then(function() {
      return fetch(event.request).then(function(response) {
        return caches.open('v1').then(function(cache) {
          cache.put(event.request, response.clone());
          return response;
        });  
      });
    }).catch(function() {
      return caches.match('');
    })
  );
});